﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TMDT_Nhom1A.DTO;
using TMDT_Nhom1A.BUS;


namespace TMDT_Nhom1A.UserControl
{
    public partial class TopSanPhamMoi : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List<ElectricDevice_DTO> list = ElectricDevice_BUS.ListNewProduct();
                List<ElectricDevice_DTO> listnew = new List<ElectricDevice_DTO>();
                for (int i = 0; i < 4; i++)
                {
                    listnew.Add(list[i]);
                }
                dltopproduct.DataSource = listnew;
                dltopproduct.DataBind();
            }
        }

        protected void dltopproduct_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string NonDiscountPrice = "";
                string DiscountPrice = "";
                LinkButton ID = (LinkButton)e.Item.FindControl("lbLinkToDetail");
                Coupon_BUS.GetPriceCouponOfElectricDevice(ID.CommandArgument, ref NonDiscountPrice, ref DiscountPrice);
                if (NonDiscountPrice != "" && DiscountPrice != "")
                {
                    e.Item.FindControl("del").Visible = true;
                    e.Item.FindControl("nondel").Visible = false;
                    Label lbDiscountPrice = (Label)e.Item.FindControl("lbDiscountPrice");
                    Label lbNonDiscountPrice = (Label)e.Item.FindControl("lbNonDiscountPrice");
                    lbDiscountPrice.Text = DiscountPrice;
                    lbNonDiscountPrice.Text = NonDiscountPrice;
                    e.Item.FindControl("pPriceCoupon").Visible = true;
                    e.Item.FindControl("pNonDiscountPrice").Visible = true;
                }
                if (NonDiscountPrice == "" && DiscountPrice == "")
                {
                    e.Item.FindControl("del").Visible = false;
                    e.Item.FindControl("nondel").Visible = true;
                }
            }
        }
    }
}